package com.ledou44.rocketmqlearn.config;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RocketMqConfig {

    private  RocketMqConfigProperties rocketMqConfig;

    @Autowired
    public void setRocketMqConfig(RocketMqConfigProperties rocketMqConfig) {
        this.rocketMqConfig = rocketMqConfig;
    }

    @Bean
    public DefaultMQProducer createRocketMqProducer() {
        DefaultMQProducer client = new DefaultMQProducer(rocketMqConfig.getGroupName());
        client.setNamesrvAddr(rocketMqConfig.getNameServerAddress());
        return client;
    }

    @Bean
    public DefaultMQPushConsumer createRocketMqConsumer() {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(rocketMqConfig.getGroupName());
        consumer.setNamesrvAddr(rocketMqConfig.getNameServerAddress());
        return consumer;
    }

}
